﻿using System;
using System.Collections.Generic;
using System.IO;

namespace Terraria
{
	// Token: 0x02000005 RID: 5
	public struct BitsByte
	{
		// Token: 0x17000021 RID: 33
		public bool this[int key]
		{
			get
			{
				return ((int)this.value & 1 << key) != 0;
			}
			set
			{
				if (value)
				{
					this.value |= (byte)(1 << key);
					return;
				}
				this.value &= ~(byte)(1 << key);
			}
		}

		// Token: 0x06000033 RID: 51 RVA: 0x0001D360 File Offset: 0x0001B560
		public BitsByte(bool b1 = false, bool b2 = false, bool b3 = false, bool b4 = false, bool b5 = false, bool b6 = false, bool b7 = false, bool b8 = false)
		{
			this.value = 0;
			this[0] = b1;
			this[1] = b2;
			this[2] = b3;
			this[3] = b4;
			this[4] = b5;
			this[5] = b6;
			this[6] = b7;
			this[7] = b8;
		}

		// Token: 0x06000034 RID: 52 RVA: 0x000064A5 File Offset: 0x000046A5
		public void ClearAll()
		{
			this.value = 0;
		}

		// Token: 0x06000035 RID: 53 RVA: 0x000064AE File Offset: 0x000046AE
		public void SetAll()
		{
			this.value = byte.MaxValue;
		}

		// Token: 0x06000036 RID: 54 RVA: 0x0001D3BC File Offset: 0x0001B5BC
		public void Retrieve(ref bool b0)
		{
			this.Retrieve(ref b0, ref BitsByte.Null, ref BitsByte.Null, ref BitsByte.Null, ref BitsByte.Null, ref BitsByte.Null, ref BitsByte.Null, ref BitsByte.Null);
		}

		// Token: 0x06000037 RID: 55 RVA: 0x0001D3F4 File Offset: 0x0001B5F4
		public void Retrieve(ref bool b0, ref bool b1)
		{
			this.Retrieve(ref b0, ref b1, ref BitsByte.Null, ref BitsByte.Null, ref BitsByte.Null, ref BitsByte.Null, ref BitsByte.Null, ref BitsByte.Null);
		}

		// Token: 0x06000038 RID: 56 RVA: 0x0001D428 File Offset: 0x0001B628
		public void Retrieve(ref bool b0, ref bool b1, ref bool b2)
		{
			this.Retrieve(ref b0, ref b1, ref b2, ref BitsByte.Null, ref BitsByte.Null, ref BitsByte.Null, ref BitsByte.Null, ref BitsByte.Null);
		}

		// Token: 0x06000039 RID: 57 RVA: 0x0001D458 File Offset: 0x0001B658
		public void Retrieve(ref bool b0, ref bool b1, ref bool b2, ref bool b3)
		{
			this.Retrieve(ref b0, ref b1, ref b2, ref b3, ref BitsByte.Null, ref BitsByte.Null, ref BitsByte.Null, ref BitsByte.Null);
		}

		// Token: 0x0600003A RID: 58 RVA: 0x0001D484 File Offset: 0x0001B684
		public void Retrieve(ref bool b0, ref bool b1, ref bool b2, ref bool b3, ref bool b4)
		{
			this.Retrieve(ref b0, ref b1, ref b2, ref b3, ref b4, ref BitsByte.Null, ref BitsByte.Null, ref BitsByte.Null);
		}

		// Token: 0x0600003B RID: 59 RVA: 0x0001D4B0 File Offset: 0x0001B6B0
		public void Retrieve(ref bool b0, ref bool b1, ref bool b2, ref bool b3, ref bool b4, ref bool b5)
		{
			this.Retrieve(ref b0, ref b1, ref b2, ref b3, ref b4, ref b5, ref BitsByte.Null, ref BitsByte.Null);
		}

		// Token: 0x0600003C RID: 60 RVA: 0x0001D4D8 File Offset: 0x0001B6D8
		public void Retrieve(ref bool b0, ref bool b1, ref bool b2, ref bool b3, ref bool b4, ref bool b5, ref bool b6)
		{
			this.Retrieve(ref b0, ref b1, ref b2, ref b3, ref b4, ref b5, ref b6, ref BitsByte.Null);
		}

		// Token: 0x0600003D RID: 61 RVA: 0x0001D4FC File Offset: 0x0001B6FC
		public void Retrieve(ref bool b0, ref bool b1, ref bool b2, ref bool b3, ref bool b4, ref bool b5, ref bool b6, ref bool b7)
		{
			b0 = this[0];
			b1 = this[1];
			b2 = this[2];
			b3 = this[3];
			b4 = this[4];
			b5 = this[5];
			b6 = this[6];
			b7 = this[7];
		}

		// Token: 0x0600003E RID: 62 RVA: 0x000064BB File Offset: 0x000046BB
		public static implicit operator byte(BitsByte bb)
		{
			return bb.value;
		}

		// Token: 0x0600003F RID: 63 RVA: 0x0001D558 File Offset: 0x0001B758
		public static implicit operator BitsByte(byte b)
		{
			return new BitsByte
			{
				value = b
			};
		}

		// Token: 0x06000040 RID: 64 RVA: 0x0001D578 File Offset: 0x0001B778
		public static BitsByte[] ComposeBitsBytesChain(bool optimizeLength, params bool[] flags)
		{
			int i = flags.Length;
			int num = 0;
			while (i > 0)
			{
				num++;
				i -= 7;
			}
			BitsByte[] array = new BitsByte[num];
			int num2 = 0;
			int num3 = 0;
			for (int j = 0; j < flags.Length; j++)
			{
				array[num3][num2] = flags[j];
				num2++;
				if (num2 == 7 && num3 < num - 1)
				{
					array[num3][num2] = true;
					num2 = 0;
					num3++;
				}
			}
			if (optimizeLength)
			{
				int num4 = array.Length - 1;
				while (array[num4] == 0 && num4 > 0)
				{
					array[num4 - 1][7] = false;
					num4--;
				}
				Array.Resize<BitsByte>(ref array, num4 + 1);
			}
			return array;
		}

		// Token: 0x06000041 RID: 65 RVA: 0x0001D634 File Offset: 0x0001B834
		public static BitsByte[] DecomposeBitsBytesChain(BinaryReader reader)
		{
			List<BitsByte> list = new List<BitsByte>();
			BitsByte item;
			do
			{
				item = reader.ReadByte();
				list.Add(item);
			}
			while (item[7]);
			return list.ToArray();
		}

		// Token: 0x06000042 RID: 66 RVA: 0x0001D66C File Offset: 0x0001B86C
		public static void SortOfAUnitTest()
		{
			MemoryStream memoryStream = new MemoryStream();
			BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
			BinaryReader reader = new BinaryReader(memoryStream);
			bool optimizeLength = false;
			bool[] array = new bool[28];
			array[3] = true;
			array[14] = true;
			BitsByte[] array2 = BitsByte.ComposeBitsBytesChain(optimizeLength, array);
			BitsByte[] array3 = array2;
			for (int i = 0; i < array3.Length; i++)
			{
				byte b = array3[i];
				binaryWriter.Write(b);
			}
			memoryStream.Position = 0L;
			BitsByte[] array4 = BitsByte.DecomposeBitsBytesChain(reader);
			string arg = "";
			string arg2 = "";
			foreach (BitsByte bitsByte in array2)
			{
				arg = arg + bitsByte + ", ";
			}
			foreach (BitsByte bitsByte2 in array4)
			{
				arg2 = arg2 + bitsByte2 + ", ";
			}
			Main.NewText("done", byte.MaxValue, byte.MaxValue, byte.MaxValue, false);
		}

		// Token: 0x0400002D RID: 45
		private static bool Null;

		// Token: 0x0400002E RID: 46
		private byte value;
	}
}
